package review

import (
	"github.com/gin-gonic/gin"
	"go.uber.org/zap"
	"goskeleton/app/global/variable"
	"goskeleton/app/model"
	"goskeleton/app/utils/response"
	"net/http"
)

type ReviewController struct {
}

func (c ReviewController) CreateReview(context *gin.Context) {
	var reviewModel model.ReviewModel

	if err := context.BindJSON(&reviewModel); err != nil {
		context.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
		variable.ZapLog.Error("解析JSON数据时出错", zap.Error(err))
		return
	}

	err := model.CreateReviewFactory("mysql").CreateReview(reviewModel)
	if err != nil {
		context.JSON(http.StatusInternalServerError, gin.H{"error": "创建评论失败"})
		variable.ZapLog.Error("创建评论失败", zap.Error(err))
		return
	}

	response.Success(context, "创建评论成功", nil)
}
